package com.bupt.ilink.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bupt.ilink.entity.FileTranscriptionTaskResponse;
import com.bupt.ilink.entity.Studyspace.CourseSource;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface CourseSourceMapper extends BaseMapper<CourseSource> {

    @Delete("""
        DELETE cs, ftti
        FROM coursesource cs
        INNER JOIN file_transcription_task_info ftti ON cs.task_id = ftti.task_id
        WHERE cs.course_id = #{courseId}
    """)
    void deleteCourseResourcesByCourseId(@Param("courseId") Long courseId);

    @Delete("""
        DELETE cs, ftti
        FROM coursesource cs
        INNER JOIN file_transcription_task_info ftti ON cs.task_id = ftti.task_id
        WHERE cs.coursesource_id = #{sourceId}
    """)
    int deleteCourseResourcesBySourCeId(@Param("sourceId") Long sourceId);
    @Delete("""
        DELETE cs, ftti
        FROM coursesource cs
        INNER JOIN file_transcription_task_info ftti ON cs.task_id = ftti.task_id
        WHERE cs.file_id = #{courseFileId}
    """)
    int deleteCourseResourcesBycourseFileId(@Param("courseFileId")Long courseFileId);
    @Delete("""
        DELETE cs
        FROM coursesource cs
        WHERE cs.coursesource_id = #{courseFileId}
    """)
    int deleteCourseResourcesBycourseSourceIdNoTask(@Param("courseFileId")Long courseFileId);
    @Delete("""
        DELETE cs
        FROM coursesource cs
        WHERE cs.file_id = #{courseFileId}
    """)
    int deleteCourseResourcesBycourseFileIdNoTask(@Param("courseFileId")Long courseFileId);

    @Select("""
        SELECT ftti.*
        FROM coursesource cs
        INNER JOIN file_transcription_task_info ftti ON cs.task_id = ftti.task_id
        WHERE cs.coursesource_id = #{sourceId}
    """
    )
    FileTranscriptionTaskResponse selectTransResultById(Long courseSourceId);
}

